﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSapce.ServiceLocation;
using SmartSpace.Core;
using SmartSpace.OA;
using SmartSpace.Web;

namespace SmartSpace.WebApp.Modules.OA.Parts
{
    public partial class ClockInPart : SsPart
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            IOAService oaService = ServiceLocator.Get<IOAService>();
            AttendanceRecord record = oaService.GetAttendanceRecord(this.Page.User.Identity.Name, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

            if (record == null)
            {
                _ctlPanelClockIn.Visible = true;
            }
            else if (record.OutTime == null)
            {
                _ctlPanelClockOut.Visible = true;
            }
            else
            {
                _ctlPanelCompleted.Visible = true;
            }
        }

        protected void _ctlBtnClockIn_Click(object sender, EventArgs e)
        {
            IOAService oaService = ServiceLocator.Get<IOAService>();
            oaService.ClockIn(this.Page.User.Identity.Name, DateTime.Now);
            Response.Redirect(this.Request.Url.ToString());
        }

        protected void _ctlBtnClockOut_Click(object sender, EventArgs e)
        {
            IOAService oaService = ServiceLocator.Get<IOAService>();
            oaService.ClockOut(this.Page.User.Identity.Name, DateTime.Now);
            Response.Redirect(this.Request.Url.ToString());
        }
    }
}